package hp.com.servlet;

import hp.com.entity.Sells;
import hp.com.entity.Users;
import hp.com.service.IndexService;
import hp.com.service.ProductService;
import hp.com.service.impl.IndexServiceImpl;
import hp.com.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/Index")
public class Index extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session= req.getSession();
        IndexService service = new IndexServiceImpl();
        try{
            List<Sells> sellsMain = service.getSellsMain();
            req.setAttribute("sellsMain",sellsMain);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        Users user = (Users) session.getAttribute("userSession");
        req.setAttribute("userSession",user);
        req.getRequestDispatcher("/ShopPage/index.jsp").forward(req,resp);
    }
}
